package edu.calpoly;
/*
 * A class to represent groups of stones.
 */

import java.util.HashSet;

@SuppressWarnings("serial")
public class Group extends HashSet<Stone>{
   private int freeSides;
   private int state;
   
   public Group(Stone piece){
	   super();
      state = piece.getState();

      add(piece);
   }
   
   /**
    * Adds the specified Stone to this set if it is not already
    * present.
    *
    * @param piece Stone to be added to this set.
    * @return <tt>true</tt> if the set did not already contain the specified
    * Stone.
    */
   public boolean add(Stone piece){
      if(super.add(piece)){
    	  updateSides();
    	  return true;
      }
      return false;
   }
   
   public int getSides(){
      return freeSides;
   }
   
   public void updateSides(){
      freeSides = 0;
      for(Stone m: this)
    	  freeSides += m.getFreeSides();
   }
   
   public void updateSidesReverse(){
      freeSides = 0;
      for(Stone m: this){
         freeSides += m.getFreeSidesReverse();
      }
   }
   
   public int getBlackNeighbors(){
      int blacks = 0;
      for(Stone s : this){
         blacks += s.getBlackNeighbors();
      }
      
      return blacks;
   }
   
   public int getWhiteNeighbors(){
      int whites = 0;
      for(Stone s : this){
         whites += s.getWhiteNeighbors();
      }
      
      return whites;
   }
}
